package com.aaa.docter.controller.api;

import com.aaa.docter.service.PatientService;
import com.aaa.docter.service.RegisteredService;
import com.aaa.docter.vo.Dvo;
import com.aaa.entity.HisPatient;
import com.aaa.entity.HisRegistration;
import com.aaa.entity.RegisteredItem;
import com.aaa.vo.Result;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/*
                门诊挂号页面 门诊挂号页面 门诊挂号页面
                门诊挂号页面  门诊挂号页面 门诊挂号页面

* */

@RestController
@RequestMapping("/doctor/patient")
public class ApiRegistered {
    @Autowired
    private RegisteredService registeredService;


    @Autowired
    private PatientService hisPatientService;


//加载身份证信息-----    通过管着身份证号查询患者信息 idCard
//http://localhost:8871/doctor/patient/getInfoByidCard/42108719900103451X

    @PostMapping("getInfoByidCard/{idCard}")
    public Result<HisPatient> list(@PathVariable String idCard){
        return registeredService.getAll(idCard);
    }


//门诊
    @PostMapping("/getRegisteredItem")
    public Result<List<RegisteredItem>>getCheckItem(   ){

        return registeredService.getList( );
    }




//  挂号收费---  判断是否有患者信息，没有则添加
//    http://localhost:8871/doctor/patient/insertPatient/
    @PostMapping("/insertPatient")
    public Result <String> insertPatient(@RequestBody Map<String,Object> map){

        HisPatient hisPatient1 = JSON.parseObject(JSON.toJSONString(map.get("a1")), HisPatient.class);
//       Object里 LinkListMap里面不支持Map转对象，需要先转成字符串对象，然后再将字符串转换成指定对象
        System.out.println("hisPatient1 ================ " + hisPatient1);

        HisRegistration hisPatient2 = JSON.parseObject(JSON.toJSONString(map.get("a2")), HisRegistration.class);
        System.out.println("hisPatient2 ============= " + hisPatient2);

        Dvo a3 = JSON.parseObject(JSON.toJSONString(map.get("a3")), Dvo.class);
        System.out.println("a3 ============================================== " + a3);

        return hisPatientService.insertXinXi(hisPatient1,hisPatient2,a3);

    }

//    载入
//    http://localhost:8871/doctor/patient/patientAllObject/HZ57715016254042112
    @GetMapping("/patientAllObject/{patientId}")
    public Result<Map<String,Object>>patientAll(@PathVariable String patientId){
        return hisPatientService.patientAll(patientId);
    }




}
